﻿using System;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenCube.Model.Enums;
using OpenCube.Model.Enums.Converters;
using OpenCube.Nbt.Specs.Mapping.Converters;

namespace OpenCube.Model.Specs.Enums.Converters
{
	[TestClass]
	internal sealed class GeneratorTypeConverterSpecs
		: SpecsForSimpleConverter<GeneratorTypeConverter, GeneratorType, string>
	{
		#region NBT values to Model values

		[TestMethod]
		public void DefaultGeneratorNameTextToEnumShouldConvertCorrectly()
		{
			ConvertToModelValue("default")
				.Should().Be(GeneratorType.Default, because: "the text default should be converter to Default");
		}

		[TestMethod]
		public void FlatGeneratorNameTextToEnumShouldConvertCorrectly()
		{
			ConvertToModelValue("flat")
				.Should().Be(GeneratorType.Flat, because: "the text flat should be converter to Flat");
		}

		[TestMethod]
		public void LargeBiomesGeneratorNameTextToEnumShouldConvertCorrectly()
		{
			ConvertToModelValue("largeBiomes")
				.Should().Be(GeneratorType.LargeBiomes, because: "the text largeBiomes should be converter to LargeBiomes");
		}

		[TestMethod]
		public void AmplifiedGeneratorNameTextToEnumShouldConvertCorrectly()
		{
			ConvertToModelValue("amplified")
				.Should().Be(GeneratorType.Amplified, because: "the text amplified should be converter to Amplified");
		}

		[TestMethod]
		public void CustomizedGeneratorNameTextToEnumShouldConvertCorrectly()
		{
			ConvertToModelValue("customized")
				.Should().Be(GeneratorType.Customized, because: "the text customized should be converter to Customized");
		}

		[TestMethod]
		public void DebugAllBlockStatesGeneratorNameTextToEnumShouldConvertCorrectly()
		{
			ConvertToModelValue("debug_all_block_states")
				.Should().Be(GeneratorType.DebugAllBlockStates, because: "the text debug_all_block_states should be converter to DebugAllBlockState");
		}

		[TestMethod]
		public void WhenAnUnknownValueIsPassedToTheConverterItThrowsFormatException()
		{
			Action act = () => ConvertToModelValue("unknown");
			act.ShouldThrow<FormatException>(because: "the input format is unknown/incorrect");
		}

		#endregion
		#region Model values to NBT values

		[TestMethod]
		public void DefaultGeneratorEnumToNameTextShouldConvertedCorrectly()
		{
			ConvertToNbtValue(GeneratorType.Default)
				.Value.Should().Be("default", because: "the enum Default should be converted to the text default");
		}

		[TestMethod]
		public void FlatGeneratorEnumToNameTextShouldConvertedCorrectly()
		{
			ConvertToNbtValue(GeneratorType.Flat)
				.Value.Should().Be("flat", because: "the enum Flat should be converted to the text flat");
		}

		[TestMethod]
		public void LargeBiomesGeneratorEnumToNameTextShouldConvertedCorrectly()
		{
			ConvertToNbtValue(GeneratorType.LargeBiomes)
				.Value.Should().Be("largeBiomes", because: "the enum LargeBiomes should be converted to the text largeBiomes");
		}

		[TestMethod]
		public void AmplifiedGeneratorEnumToNameTextShouldConvertedCorrectly()
		{
			ConvertToNbtValue(GeneratorType.Amplified)
				.Value.Should().Be("amplified", because: "the enum Amplified should be converted to the text amplified");
		}

		[TestMethod]
		public void CustomizedGeneratorEnumToNameTextShouldConvertedCorrectly()
		{
			ConvertToNbtValue(GeneratorType.Customized)
				.Value.Should().Be("customized", because: "the enum Customized should be converted to the text customized");
		}

		[TestMethod]
		public void DebugAllBlockStatesGeneratorEnumToNameTextShouldConvertedCorrectly()
		{
			ConvertToNbtValue(GeneratorType.DebugAllBlockStates)
				.Value.Should().Be("debug_all_block_states", because: "the enum DebugAllBlockStates should be converted to the text debug_all_block_states");
		}

		[TestMethod]
		public void InvalidGeneratorEnumToNameTextShouldThrownArgumentOutOfRangeException()
		{
			Action act = () => ConvertToNbtValue((GeneratorType)3883);
			act.ShouldThrow<ArgumentOutOfRangeException>( because: "The value 3883 is not a known enum for GeneratorType");
		}

		#endregion
	}
}
